<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>商品列表</title>
    <!-- jquery -->
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <!-- bootstrap -->
    <link rel="stylesheet" type="text/css" th:href="@{/bootstrap/css/bootstrap.min.css}"/>
    <script type="text/javascript" th:src="@{/bootstrap/js/bootstrap.min.js}"></script>
    <!-- layer -->
    <script type="text/javascript" th:src="@{/layer/layer.js}"></script>
    <!-- common.js -->
    <script type="text/javascript" th:src="@{/js/common.js}"></script>
    <style>
        #title {
            font-size: 18px;
            color: #2aabd2;
        }

        .title2 {
            font-size: 16px;
            color: black;
        }

        .inner {
            font-size: 17px;
            color: red;
        }
        .apply-button {
            background-color: red; /* Green */
            border: none;
            color: white;
            padding: 15px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
        }
        .direct-button {
            background-color: #4CAF50; /* Green */
            border: none;
            color: white;
            padding: 15px 32px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
        }
        #list-parant #btn-td {
            vertical-align: middle;
            text-align: center;
        }
    </style>
</head>
<body>
<img src="/img/img.png" width="20%" height="20%">
<!--<img src="http://www.fwwb.org.cn/static/images/logo.jpg" style="float: right">-->
<div id="list-parant" class="panel panel-default">
    <div class="panel-heading">秒杀商品列表</div>
    <table class="table" id="goodslist">
        <!--        <tr>-->
        <!--            <td>商品名称</td>-->
        <!--            <td>商品图片</td>-->
        <!--            <td>商品原价</td>-->
        <!--            <td>秒杀价</td>-->
        <!--            <td>库存数量</td>-->
        <!--            <td>详情</td>-->
        <!--        </tr>-->
        <tr th:each="goods,goodsStat : ${goodsList}">
            <td>
                <b id="title" th:text="${goods.goodsName}"></b><br/>
                <b class="title2">秒杀开始时间:</b>
                <span class="inner" th:text="${#dates.format(goods.startDate,'yyyy年MM月dd日 HH:mm:ss')}"></span><br/>
                <b class="title2">秒杀结束时间:</b>
                <span class="inner" th:text="${#dates.format(goods.endDate,'yyyy年MM月dd日 HH:mm:ss')}"></span><br/>
                <b class="title2">限购数量:</b>
                <span class="inner" th:text="${goods.limitCount}"></span><br/>
                <b class="title2">单价:</b>
                <span class="inner" th:text="${goods.seckillPrice}"></span><br/>
                <b class="title2">物资储备余量:</b>
                <span class="inner" th:text="${goods.stockCount}"></span><br/>
                <b class="title2">发货地址:</b>
                <span class="inner" th:text="${goods.postAddress}"></span><br/>
                <b class="title2">发货单位:</b>
                <span class="inner" th:text="${goods.postCompany}"></span><br/>
                <b class="title2">配送时间:</b>
                <span class="inner" th:text="${#dates.format(goods.postTime,'yyyy年MM月dd日 HH:mm:ss')}"></span><br/>
            </td>

            <td><img  th:src="@{${goods.goodsImg}}" width="230px" height="230px"/></td>
            <td id="btn-td">
                <button class="apply-button" th:value="${goods.id}" onclick="doApplication(this.value)">申请</button>
            </td>
            <td id="btn-td">
                <button class="direct-button" th:value="${goods.id}" onclick="toDetail(this.value)">详情</button>
            </td>
        </tr>
    </table>
</div>
</body>
<script>

    function doApplication(goodsId) {
        console.log(goodsId)
        $.ajax({
            url: '/application/doApplication',
            type: "GET",
            data: {
                goodsId: goodsId
            },
            success: function (data) {
                if (data.code == 200) {
                    layer.msg(data.object);
                } else {
                    layer.msg(data.message);
                }
            }, error: function () {
                layer.msg("客户端请求出错");
            }
        });
    }

    function toDetail(goodsId) {
        $.ajax({
            url: '/application/check',
            type: "GET",
            data: {
                goodsId: goodsId
            },
            success: function (data) {
                if (data.code == 200) {
                    layer.msg("申请通过");
                    window.location.href = "/goodsDetail.html?goodsId=" + goodsId;
                } else {
                    layer.msg(data.message);
                }
            }, error: function () {
                layer.msg("客户端请求出错");
            }
        });
    }
</script>
</html>